package com.xjl.shujujiegou;

import java.util.Stack;

/**
 * @描述： 用栈实现队列
 * @作者： 许JIAN林
 */
public class StackQueue {
    private Stack<Integer> push;
    private Stack<Integer> pop;

    public StackQueue() {
        push = new Stack<>();
        pop = new Stack<>();
    }

    public void push(int num){
        push.push(num);
    }
    public Integer pop(){
        dao();
       return pop.pop();
    }
    public Integer peek(){
        dao();
        return pop.peek();
    }

    private void dao(){
        if (!pop.isEmpty()) {
            return;
        }
        while (!push.isEmpty()) {
            pop.push(push.pop());
        }

    }

}
